﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyLib {
	/// <summary>
	/// 
	/// </summary>
	public static class EnumerableExtensions {
		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="TValue"></typeparam>
		/// <param name="enu"></param>
		/// <param name="act"></param>
		/// <returns></returns>
		public static IEnumerable<TValue> Each<TValue>(this IEnumerable<TValue> enu, Action<TValue> act) {
			if (enu == null) {
				yield break;
			}

			foreach (var item in enu) {
				act(item);

				yield return item;
			}
		} // end of Each.

		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="TValue"></typeparam>
		/// <param name="enu"></param>
		/// <param name="mapper"></param>
		/// <returns></returns>
		public static IEnumerable<TValue> Each<TValue>(this IEnumerable<TValue> enu, Func<TValue, TValue> mapper) {
			if (enu == null) {
				yield break;
			}

			foreach (var item in enu) {
				yield return mapper(item);
			}
		} // end of Each.
	} // end of EnumerableExtensions.
}
